// 系统管理相关类型定义

// 备份信息
export interface BackupInfo {
  lastBackup: string
  totalBackups: number
  totalSize: number
}

// 备份记录
export interface BackupRecord {
  id: string
  filename: string
  backup_type: 'full' | 'incremental'
  size: number
  created_at: string
  status: 'completed' | 'failed' | 'running'
  description?: string
}

// 清理统计
export interface CleanupStats {
  obsoleteRecords: number
  tempFiles: number
  storageToFree: number
}

// 清理选项
export interface CleanupOption {
  key: string
  label: string
  description?: string
}

// 维护记录
export interface MaintenanceRecord {
  id: string
  type: 'backup' | 'restore' | 'cleanup'
  description: string
  status: 'completed' | 'failed' | 'running' | 'pending'
  created_at: string
  completed_at?: string
  operator: string
  result?: any
}

// 备份创建请求
export interface BackupCreateRequest {
  backup_type: 'full' | 'incremental'
  description?: string
}

// 备份恢复请求
export interface BackupRestoreRequest {
  backup_id: string
  create_backup_before_restore?: boolean
}

// 清理执行请求
export interface CleanupExecuteRequest {
  cleanup_types: string[]
  dry_run: boolean
}

// 自动备份配置请求
export interface AutoBackupConfigRequest {
  enabled: boolean
  interval: string
}

// 维护历史查询参数
export interface MaintenanceHistoryParams {
  type?: string
  page: number
  size: number
}

// 系统状态
export interface SystemStatus {
  server: {
    status: 'running' | 'stopped' | 'error'
    uptime: number
    cpu_usage: number
    memory_usage: number
    disk_usage: number
  }
  database: {
    status: 'connected' | 'disconnected' | 'error'
    connection_count: number
    query_time_avg: number
  }
  application: {
    status: 'healthy' | 'warning' | 'error'
    active_users: number
    request_count: number
  }
}

// 性能指标
export interface PerformanceMetrics {
  time_range_hours: number
  cpu_usage: Array<{
    timestamp: string
    value: number
  }>
  memory_usage: Array<{
    timestamp: string
    value: number
  }>
  disk_usage: Array<{
    timestamp: string
    value: number
  }>
  response_time: Array<{
    timestamp: string
    value: number
  }>
}

// 实时数据
export interface RealtimeData {
  current_time: string
  system_load: number
  active_connections: number
  request_rate: number
  error_rate: number
}

// 日志查询参数
export interface LogQueryParams {
  log_type?: string
  level?: string
  start_time?: string
  end_time?: string
  user_id?: number
  keyword?: string
  ip_address?: string
  page: number
  size: number
}

// 日志记录
export interface LogRecord {
  id: string
  timestamp: string
  type: string
  level: string
  operation: string
  description: string
  user_id?: number
  username?: string
  target_type?: string
  target_id?: string
  client_ip?: string
  user_agent?: string
}

// 日志分析请求
export interface LogAnalysisRequest {
  analysis_type: 'activity' | 'error' | 'security' | 'performance'
  time_range: number
  group_by: 'hour' | 'day' | 'user' | 'ip' | 'operation'
}

// 日志导出请求
export interface LogExportRequest {
  export_format: 'json' | 'csv'
  log_type?: string
  start_time?: string
  end_time?: string
  max_records: number
}

// 日志统计
export interface LogStatistics {
  time_range_hours: number
  total_logs: number
  type_distribution: Record<string, number>
  top_active_users: Array<{
    user_id: number
    username: string
    activity_count: number
  }>
  hourly_distribution: Array<{
    hour: number
    timestamp: string
    count: number
  }>
  statistics_generated_at: string
}

// 集成配置
export interface IntegrationConfig {
  type: string
  enabled: boolean
  config: Record<string, any>
  last_test?: {
    success: boolean
    message: string
    test_time: string
  }
}

// 集成列表
export interface IntegrationList {
  integrations: Record<string, IntegrationConfig>
  total_count: number
  enabled_count: number
}

// 集成操作请求
export interface IntegrationActionRequest {
  action: 'create' | 'update' | 'delete' | 'enable' | 'disable'
  integration_type: string
  config_data?: Record<string, any>
}

// 连接测试请求
export interface ConnectionTestRequest {
  integration_type: string
  config_data?: Record<string, any>
}

// 数据同步请求
export interface SyncDataRequest {
  integration_type: string
  sync_type: 'full' | 'incremental'
}

// API监控数据
export interface ApiMonitoringData {
  time_range: {
    start: string
    end: string
    hours: number
  }
  summary: {
    total_requests: number
    success_requests: number
    error_requests: number
    success_rate_percent: number
  }
  response_time: {
    average_ms: number
    median_ms: number
    p95_ms: number
    p99_ms: number
    max_ms: number
  }
  top_endpoints: Array<{
    endpoint: string
    request_count: number
    percentage: number
  }>
  grouped_data: {
    group_by: string
    data: any[]
  }
}

// API统计数据
export interface ApiStatistics {
  time_range_hours: number
  request_stats: {
    total_requests: number
    unique_users: number
    unique_ips: number
    error_requests: number
    error_rate_percent: number
  }
  distributions: {
    hourly: Array<{
      hour: number
      timestamp: string
      request_count: number
    }>
    status_codes: Array<{
      status_code: string
      count: number
      percentage: number
    }>
  }
  generated_at: string
}

// 访问控制规则
export interface AccessRule {
  rule_id: string
  name: string
  rule_type: string
  conditions: Record<string, any>
  action: 'allow' | 'deny'
  description?: string
  enabled: boolean
  created_by: string
  created_at: string
  updated_by?: string
  updated_at?: string
}

// 访问规则列表
export interface AccessRuleList {
  rules: AccessRule[]
  total_count: number
  active_count: number
}

// 访问规则请求
export interface AccessRuleRequest {
  action: 'create' | 'update' | 'delete' | 'enable' | 'disable'
  access_config: Record<string, any>
}

// API报告请求
export interface ApiReportRequest {
  report_type: 'usage' | 'security' | 'performance' | 'error'
  time_range: number
  filters?: Record<string, any>
}

// 通用API响应
export interface ApiResponse<T = any> {
  success: boolean
  message: string
  data: T
}

// 分页响应
export interface PaginatedResponse<T = any> {
  items: T[]
  total: number
  page: number
  size: number
  pages: number
}